angular.module('goods-addypk',['flow-div'])

.controller 'GoodsAddypkCtrl', ($scope,$ionicViewSwitcher,$ionicHistory,$http,userData,$ionicPopup,$stateParams,showToast,goodsInfo) ->
    $scope.item = $stateParams.obj
    console.log $scope.item
    console.log $ionicHistory.backView().stateName
    _.extend $scope,
        formValidation: ->
            price = $scope.item.defaultprice.match(/^[0-9]+([.][0-9]+){0,1}$/)==null
            if price
                showToast '请输入正确的售价'
                return false
            else
                return true
        goBack: ->
            $ionicViewSwitcher.nextDirection('back')
            $ionicHistory.goBack()
        goodsInWare: (item)->
            if $scope.formValidation()
                $http.post('/updshop/',{action:'joinware',userid:userData.getToken(),id:item.id,saleprice:item.defaultprice,jointype:'0'})
                .success (resp) ->
                    if resp?.status == '0'
                        showToast '商品已添加到仓库中'
                        item.isadd = '1'
                    else
                        showToast resp.msg
                .error ->
                    showToast '网络异常,请检查网络是否连接'
        goodsInmall: (item)->
            if $scope.formValidation()
                $http.post('/updshop/',{action:'joinware',userid:userData.getToken(),id:item.id,saleprice:item.defaultprice,jointype:'1'})
                .success (resp) ->
                    if resp?.status == '0'
                        showToast '商品已添加到店铺中'
                        item.isadd = '1'
                        console.log item
                    else
                        showToast resp.msg
                .error ->
                    showToast '网络异常,请检查网络是否连接'


